package edu.pku.sei.modeler.neditor.part;

import java.beans.PropertyChangeEvent;

import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.EditPolicy;

import edu.pku.sei.gefcommon.common.resourceManager.ResourceGroupManager;
import edu.pku.sei.modeler.model.notation.core.NotationPackage;
import edu.pku.sei.modeler.neditor.part.policy.NodeDeleteEditPolicy;


public class TextObjectEditPart extends AbstractMetaElementPart {

	@Override
	protected IFigure createFigure() {
		edu.pku.notation.runtime.draw2d.TextFigure l = new edu.pku.notation.runtime.draw2d.TextFigure();
		return l;
	}
	@Override
	protected void createEditPolicies() {
		installEditPolicy(EditPolicy.COMPONENT_ROLE,new NodeDeleteEditPolicy());
	}
	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		String type = evt.getPropertyName();
		if(NotationPackage.TEXTOBJECT_TEXT.equals(type)){
			this.refreshVisuals();
		} else if(NotationPackage.TEXTOBJECT_TEXTMAPPING.equals(type)){
			this.refreshVisuals();
		} else super.propertyChange(evt);
	}
	@Override
	protected void refreshVisuals() {
		org.eclipse.draw2d.Label figure = (org.eclipse.draw2d.Label)getFigure();
		edu.pku.sei.modeler.model.notation.shape.TextObject model = (edu.pku.sei.modeler.model.notation.shape.TextObject)getModel();
		//Rectangle r = model.getBound();
		//figure.setLocation(r.getLocation());
		//figure.setSize(r.width, r.height);
		figure.setBounds(model.getBound());	
		figure.setForegroundColor(ResourceGroupManager.getSWTColor(model.getLineColor()));
		figure.setBackgroundColor(ResourceGroupManager.getSWTColor(model.getFillColor()));
		
		figure.setText(model.getText());
	}

	
	

}
